package com.soft.base.spring.redis;

import com.alibaba.fastjson.JSON;
import com.soft.base.contract.LazyValue;
import com.soft.base.contract.LazyValueFacade;
import com.soft.base.util.Md5Util;
/**
 * class
 *
 * @author user
 * @date 2020/06/05
 */
public class RedisLazyValueFacade implements LazyValueFacade {

    public RedisLazyValueFacade() {
        LazyValue.boot(this);
    }

    @Override
    public String hash(String key, Callback callback) {
        return RedisUtil.remember(String.format("LazyValue.%s", key), 3600, () -> Md5Util.hexString(JSON.toJSONString(callback.callback())));
    }

    @Override
    public void notifyChange(String key) {
        RedisUtil.delete(String.format("LazyValue.%s", key));
    }
}
